package com.demo.web.modules.uiv;

import com.demo.common.constant.api.base.IDEntity;
import com.demo.common.constant.api.UivBasicVOAPIConstant;
import com.demo.common.result.ResponseInfo;
import com.demo.common.result.ResultVo;
import com.demo.dao.uiv.entity.UivComponentNode;
import com.demo.dao.uiv.model.UivQueryItemVO;
import com.demo.service.uiv.UivBasicVOService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/uiv/basic_vo")
public class UivBasicVOController {
    @Autowired
    private UivBasicVOService myService;

    @GetMapping("/test")
    public String test(){
        return "hello, you are in UivBasicVO test!";
    }


    //菜单分类树
    @RequestMapping(value = UivBasicVOAPIConstant.UIV_MENU_VO_TREE, method = RequestMethod.POST)
    public ResultVo getMenuVOTree(){
        return ResponseInfo.<Object>success(myService.getMenuVOTree());
    }

    //项目列表树
    @RequestMapping(value = UivBasicVOAPIConstant.UIV_PROJECT_VO_TREE, method = RequestMethod.POST)
    public ResultVo getProjectVOTree(){
        return ResponseInfo.<Object>success(myService.getProjectVOTree());
    }

    //页面列表树
    @RequestMapping(value = UivBasicVOAPIConstant.UIV_PAGE_VO_TREE, method = RequestMethod.POST)
    public ResultVo getPageVOTree(){
        return ResponseInfo.<Object>success(myService.getPageVOTree());
    }

    //模板列表树
    @RequestMapping(value = UivBasicVOAPIConstant.UIV_MOD_VO_TREE, method = RequestMethod.POST)
    public ResultVo getModVOTree() {
        return ResponseInfo.<Object>success(myService.getModVOTree());
    }

    //数据字典类型树
    @RequestMapping(value = UivBasicVOAPIConstant.UIV_DICT_TYPE_VO_TREE, method = RequestMethod.POST)
    public ResultVo getDictionaryTypeVOTree(@RequestBody IDEntity<Long> idt){
        return ResponseInfo.<Object>success(myService.getDictionaryTypeVOTree(idt.getId()));
    }

    //读取组件树
    @RequestMapping(value = UivBasicVOAPIConstant.UIV_COM_VO_LIST, method = RequestMethod.POST)
    public ResultVo getComponentNodeById(@RequestBody IDEntity<Long> idt) {
        //System.out.println(idt.getId());
        return ResponseInfo.<Object>success(myService.getComponentNodeById(idt.getId()));
    }

    //根据Url查询图元
    @RequestMapping(value = UivBasicVOAPIConstant.UIV_TUPLE_SEARCH_VO_LIST_API, method = RequestMethod.POST)
    public ResultVo getTupleByURL(@RequestBody Map<String, String> map) {
        System.out.print(map);
        return ResponseInfo.<Object>success(myService.getTupleByURL(map.get("url")));
    }

    //根据项目ID读取变量信息
    @RequestMapping(value = UivBasicVOAPIConstant.UIV_VAR_SEARCH_LIST, method = RequestMethod.POST)
    public ResultVo getVarItemVOByProjectId(@RequestBody UivQueryItemVO param) {
        System.out.println(param);
        return ResponseInfo.<Object>success(myService.getVarItemVOByParam(param));
    }

    //根据变量ID读取相关信息
    @RequestMapping(value = UivBasicVOAPIConstant.UIV_VAR_VO_LIST, method = RequestMethod.POST)
    public ResultVo getVarItemVOById(@RequestBody IDEntity<Long> idt) {
        return ResponseInfo.<Object>success(myService.getVarItemVOById(idt.getId()));
    }
}
